package work20241216;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author zdl
 * @date 2024/12/16
 */
public class Demo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("Jack");
        list.add("Tom");
        list.add("Rose");
        list.add("Helen");

        //fori遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        //增强for循环
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("======================================");
        // Iterator 迭代器
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
}
